package shapewar.engine.presenter;

import java.util.Comparator;
import java.util.Iterator;
import java.util.TreeSet;

import android.os.Handler;

public class TreeSet1<T> extends TreeSet<T>{
	public Object obj_add[] = new Object[50];
	public Object obj_remove[] = new Object[50];
	public int add_i = 0,add_j = 0;
	public int remove_i = 0,remove_j = 0;
	public TreeSet1(Comparator<T> c) {
		super(c);
	}
	
	int maxnum = 0;
	public void add(T object,boolean valid) {
		obj_add[add_i++%obj_add.length] = object;
		if(valid)valid();
	}
	
	public void remove(Object object,boolean valid) {
		obj_remove[remove_i++%obj_remove.length] = object;
		if(valid)valid();
	}
	
	@SuppressWarnings("unchecked")
	public void valid() {
		if(maxnum<(add_i-add_j)){
			maxnum = add_i-add_j;
		}
		
		while(add_j<add_i){
			add((T) obj_add[add_j++%obj_add.length]);
		}
		
		while(remove_j<remove_i){
			remove((T) obj_remove[remove_j++%obj_remove.length]);
		}
	}
	
}